package main

import (
	"fmt"
	"geeorm/session"
	_ "github.com/mattn/go-sqlite3"

	"geeorm"
)

func main() {
	engine, err := geeorm.NewEngine("sqlite3", "gee.db")
	if err != nil {
		panic(err)
	}
	defer engine.Close()
	s := engine.NewSession()

	//if testInsert(err, s) {
	//	return
	//}

	testFind(s)
	//engine.NewSession()
	//session := engine.NewSession()
	//session.Model(&User{})
	//session.CreateTable()
	//
	//xiaoming := &User{"xiaoming", 18}
	//_, err = session.Insert(xiaoming)
	//if err != nil {
	//	return
	//}
	//
	//session.Find(&User{})

}

func testFind(s *session.Session) {
	//传入一个切片指针，查询的结果保存在切片中。
	var desc []User
	s.Find2(&desc)
	fmt.Println(desc)
}

func testInsert(err error, s *session.Session) bool {
	u1 := &User{Name: "Tom24", Age: 18}
	//u2 := &User{Name: "Sam21", Age: 25}
	if _, err = s.Insert2(u1); err != nil {
		return true
	}
	return false
}

type User struct {
	Name string `geeorm:"PRIMARY KEY"`
	Age  int
}
